//获取通用资源类
const { mysql } = require('../qcloud')

var ctr = {
  //获取标签类型
  leixing: async (ctx, next) => {
    //search
    let jg = await mysql.select().table('leixing');
    //var jg = test.create();
    ctx.state.data = {
      msg: 'leixing jg:',
      jg: jg
    }
  },
  //获取置顶设置
  zdts: async (ctx, next) => {
    //search
    let zdtsjg = await mysql.select().table('zhiding');
    ctx.state.data = {
      msg: 'zdts jg:',
      jg: zdtsjg
    };
  }
};
var rq = {};
module.exports = async (ctx, next) => {
  Object.assign(rq, ctx.query, ctx.request.body, ctx.params);
  var fun = ctr[rq.action];
  if (typeof (fun) == "function") {
    try {
      await fun(ctx, next);
      // await  mysql('test').select('id').then(res => {
      //   ctx.state.data = res;
      // })
    } catch (e) {
      ctx.state.data = {
        ac: rq.action,
        ty: typeof (fun),
        error: e && e.message ? e.message : e.toString()
      }
    }

  } else {
    ctx.state.data = {
      ac: rq.action,
      ty: typeof (fun)
    }
  }
}